package com.virtium.vpc.action.controller;

import java.util.ArrayList;
import java.util.Iterator;

import com.virtium.vpc.dao.DAOFactory;
import com.virtium.vpc.dao.VpcTechnologyDAO;
import com.virtium.vpc.hibernate.model.VpcTechnology;

public class VpcTechnologyManager {
	private static ArrayList<VpcTechnology> arrVpcTechnology = null;

	public static ArrayList<VpcTechnology> getAll() {
		try {
			if (arrVpcTechnology != null && arrVpcTechnology.size() > 0)
				return arrVpcTechnology;
			VpcTechnologyDAO vpcTechnologyDAO = DAOFactory.getInstance()
					.getVpcTechnologyDAO();
			arrVpcTechnology = new ArrayList<VpcTechnology>();
			arrVpcTechnology.addAll(vpcTechnologyDAO.findAll());
		} catch (Exception ex) {
			System.out.println(ex.getMessage());
		}
		return arrVpcTechnology;
	}
	
	public static String getTextByID(int id){
		getAll();
		Iterator<VpcTechnology> iterTech = arrVpcTechnology.listIterator();
		while(iterTech.hasNext()){
			VpcTechnology vpcTechnology = iterTech.next();
			if(vpcTechnology.getId().equals(id))return vpcTechnology.getText();
			
		}
		return "";
	}
	
	public static void AddNew(String text){
		try{
			VpcTechnology object = new VpcTechnology();
			object.setText(text);
			VpcTechnologyDAO ObjectDAO = DAOFactory.getInstance().getVpcTechnologyDAO();
			ObjectDAO.save(object);
			arrVpcTechnology = null;
		}catch(Exception ex){
			
		}
	}
	
	public static void Delete(int id){
		try{
			
			VpcTechnologyDAO ObjectDAO = DAOFactory.getInstance().getVpcTechnologyDAO();
			VpcTechnology object = ObjectDAO.findById(id);
			ObjectDAO.delete(object);
			arrVpcTechnology = null;
		}catch(Exception ex){
			
		}
	}
}
